package com.xiaoai.redis.controller;

import com.xiaoai.redis.entity.SysUser;
import com.xiaoai.redis.service.SysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 用户管理
 * @author ludangxin
 * @date 2021/8/11
 */
@RestController
@RequestMapping("user")
@RequiredArgsConstructor
public class UserController {
   private final SysUserService userService;

   @GetMapping
   public List<SysUser> queryAll() {
      return userService.queryAll();
   }

   @GetMapping("{userId}")
   public SysUser getUserInfo(@PathVariable Long userId) {
      return userService.getUserInfo(userId);
   }

   @PostMapping
   public String add(@RequestBody SysUser user) {
      userService.add(user);
      return "新增成功～";
   }

   @PutMapping("{userId}")
   public String update(@PathVariable Long userId, @RequestBody SysUser user) {
      userService.update(userId, user);
      return "更新成功～";
   }

   @DeleteMapping("{userId}")
   public String del(@PathVariable Long userId) {
      userService.delete(userId);
      return "删除成功～";
   }
}